package heima.lm.oschina.ui.view;

import android.content.Context;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import heima.lm.oschina.R;

/**
 * Created by Administrator on 2017/4/2.
 */

public class DiscoverItemView extends LinearLayout {
    private ImageView mIvDiscover;
    private TextView mTvDiscover;
    private DisItemOnClickListener mItemOnClickListener;

    public DiscoverItemView(Context context) {
        this(context, null);
    }

    public DiscoverItemView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs, 0);
        View view = LayoutInflater.from(context).inflate(R.layout.item_discover, this);
        mIvDiscover = (ImageView) view.findViewById(R.id.div_iv_discover);
        mTvDiscover = (TextView) view.findViewById(R.id.div_tv_discover);
    }

    public DiscoverItemView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        return true;
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        switch (event.getAction()) {
            case MotionEvent.ACTION_MOVE:
                break;
            case MotionEvent.ACTION_DOWN:
                break;
            case MotionEvent.ACTION_UP:
                if (mItemOnClickListener != null)
                    mItemOnClickListener.onClick(this);
                break;

        }
        return super.onTouchEvent(event);
    }

    @Override
    public void setClickable(boolean clickable) {
        super.setClickable(clickable);
    }

    //设置图片
    public void setImageResource(int resId) {
        mIvDiscover.setImageResource(resId);
    }

    //设置文字内容
    public void setTextContent(String str) {
        mTvDiscover.setText(str);
    }

    //设置文字大小
    public void setTextSize(int size) {
        mTvDiscover.setTextSize(size);
    }

    public void setItemOnClickListener(DisItemOnClickListener itemOnClickListener) {
        this.mItemOnClickListener = itemOnClickListener;
    }

    public static interface DisItemOnClickListener {
        void onClick(View v);
    }

}
